package com.zxn.dorm.view.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;
import com.zxn.dorm.R;
import com.zxn.dorm.entity.MemberBeanInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zxn on 2019/6/4.
 */
public class MemberManageAdapter extends BaseQuickAdapter<MemberBeanInfo, MemberManageAdapter.MemberManageVH> implements BaseQuickAdapter.OnItemChildClickListener {
    public MemberManageAdapter() {
        super(R.layout.item_member_manage);
        setOnItemChildClickListener(this);
    }

    @Override
    protected void convert(MemberManageVH helper, MemberBeanInfo item) {
        helper.tvMemberName.setText(item.memberName);
        helper.tvMobile.setText(item.mobile);
        helper.tvTotalBalancePoint.setText("男"+"170cm");
        helper.addOnClickListener(R.id.btn_delete);
        helper.addOnClickListener(R.id.cl_item);
    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        if (view.getId() == R.id.btn_delete) {
            if (view.getParent() instanceof SwipeMenuLayout) {
                SwipeMenuLayout mSwipeMenuLayout = (SwipeMenuLayout) view.getParent();
                mSwipeMenuLayout.smoothClose();
            }
            if (null != mOnDeleteItemListener) {
                mOnDeleteItemListener.onItemDeleteClick(position);
            }
        }else  if (view.getId() == R.id.cl_item) {
            if (null != mOnDeleteItemListener) {
                mOnDeleteItemListener.onItemClick(position);
            }
        }
    }

    static class MemberManageVH extends BaseViewHolder {
        @BindView(R.id.iv_head_img_url)
        ImageView ivHeadImgUrl;
        @BindView(R.id.tv_member_name)
        TextView tvMemberName;
        @BindView(R.id.tv_mobile)
        TextView tvMobile;
        @BindView(R.id.tv_total_balance_point)
        TextView tvTotalBalancePoint;
        @BindView(R.id.iv_birthday)
        ImageView ivBirthday;

        MemberManageVH(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    private OnDeleteItemListener mOnDeleteItemListener;

    public interface OnDeleteItemListener {
        void onItemDeleteClick(int position);

        void onItemClick(int position);
    }

    public void setOnDeleteItemListener(OnDeleteItemListener listener) {
        this.mOnDeleteItemListener = listener;
    }

}
